rm(list=ls())

##############################################################################
# APPENDIX B7 TABLE 1
##############################################################################

# load packages
#library(texreg)

# load data 
load("data/eurepoc_year_attacks.RData")

##############
# RUN MODELS #
##############

#model 1 (eurepoc attacks incidents)
m1 <- lm(attacks ~ treat + factor(country_spell), data = eurepoc_year_data)

# create prior year treatment variables 
eurepoc_year_data$treat2 <- ifelse(eurepoc_year_data$candidate & eurepoc_year_data$T_1, 1, 0 )
eurepoc_year_data$treat3 <- ifelse(eurepoc_year_data$candidate & eurepoc_year_data$T_2, 1, 0 )
eurepoc_year_data$treat4 <- ifelse(eurepoc_year_data$candidate & eurepoc_year_data$T_3, 1, 0 ) 

# prior year models 
m1 <- lm(attacks ~ treat + factor(country_spell), data = eurepoc_year_data)
m2 <- lm(attacks ~ treat2 + factor(country_spell), data = eurepoc_year_data)
m3 <- lm(attacks ~ treat3 + factor(country_spell), data = eurepoc_year_data)
m4 <- lm(attacks ~ treat4 + factor(country_spell), data = eurepoc_year_data)

################
# CREATE TABLE #
################
appendB7_tab1 <- screenreg(list(m1, m2, m3, m4), custom.coef.map = list("treat" = "candidate", "treat2" = "candidate",
"treat3" = "candidate", "treat4" = "candidate"),
omit.coef = c("country_spell"),
custom.gof.rows = list("Country Spell FE" = c("YES", "YES","YES", "YES")), digits = 3, 
stars = c(0.001, 0.01, 0.05, 0.1))

print(appendB7_tab1)

# script complete message 
print("appendB7_tab1 complete")